// $Id: interface.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#define XPCOM_SOURCE

#include <xpcom/config.hpp>
#include <xpcom/assert.hpp>
#include <xpcom/exception.hpp>
#include <xpcom/interface.hpp>

namespace xpcom {

int interface_instance_compare(interface* p1, interface* p2)
{
    if (p1 == p2)
        return 0;

    interface* i1 = 0;
    interface* i2 = 0;

    if (p1) {
        p1->query_interface(&i1) | throw_exception; // qi to interface must success
        XPCOM_ASSERT(i1);
        if (i1)
            i1->release();
    }

    if (p2) {
        p2->query_interface(&i2) | throw_exception;
        XPCOM_ASSERT(i2);
        if (i2)
            i2->release();
    }

    return i1 < i2 ? -1 : (i1 > i2 ? 1 : 0);
}

} // namespace xpcom
